package edu.iyte.ceng316.ui.phonebook.right;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import edu.iyte.ceng316.ui.phonebook.mediator.IPhoneBookMediator;


public class PersonButtonPanel extends JPanel implements ActionListener{
	JButton newPersonButton;
	JButton deletePersonButton;
	private IPhoneBookMediator iPhoneBookMediator;
	/**
	 * Create the panel.
	 */
	public PersonButtonPanel() {
		setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		newPersonButton = new JButton("New");
		newPersonButton.addActionListener(this);
		add(newPersonButton);
		
		deletePersonButton = new JButton("Delete");
		deletePersonButton.addActionListener(this);
		deletePersonButton.setEnabled(false);
		add(deletePersonButton);

	}
	public JButton getNewPersonButton() {
		return newPersonButton;
	}
	public JButton getDeletePersonButton() {
		return deletePersonButton;
	}
	public void setIPhoneBookMediator(IPhoneBookMediator iPhoneBookMediator) {
		this.iPhoneBookMediator = iPhoneBookMediator;
	}
	
	public void actionPerformed(ActionEvent e) {
	  if(e.getSource()==newPersonButton){
		createPerson();
	  }
		
	  else if(e.getSource()==deletePersonButton){
		deletePerson();
	  }
				
	}
	
	public void createPerson(){
	   iPhoneBookMediator.createPerson();
	}
	
	public void deletePerson(){
	   iPhoneBookMediator.deletePerson();
	}

}
